package io.jft.doll.wxapi

import android.graphics.Bitmap
import com.g.base.appContent
import com.g.base.extend.toast
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.tencent.mm.opensdk.modelmsg.WXImageObject
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage
import io.jft.doll.api.weChatApi

fun wxBitmapShare(bitmap: Bitmap, sharedWx: Boolean) {
    val wxImageObject = WXImageObject(bitmap)
    val wxMediaMessage = WXMediaMessage()
    wxMediaMessage.mediaObject = wxImageObject
    bitmap.recycle()
    val req = SendMessageToWX.Req()
    req.transaction = System.currentTimeMillis().toString()
    req.message = wxMediaMessage
    req.scene = if (sharedWx) SendMessageToWX.Req.WXSceneSession else SendMessageToWX.Req.WXSceneTimeline
    if (!weChatApi.sendReq(req)) {
        appContent.toast("无法打开微信 分享失败~")
    }
}